<?php

class authorController {
	
	function __construct() {
	}
	
	public function render( $tplname, $data = array() ) {
		$block1 = App::me()->viewPath.DIRECTORY_SEPARATOR.'author'.DIRECTORY_SEPARATOR.$tplname;

		$tpl = App::me()->tpl;
		$tpl->assign('block1', $block1);
		$tpl->assign('active_menu', '2');
		$tpl->assign('data', $data);
		$tpl->display('layout1.tpl');
	}
	
	public function index() {		
		$model = new author;
		$this->render('index', $model->select() );
	}
	
	public function create() {
		$model = new author;
		if( !isset( $_POST['aut_id'] ) ) {
			$data = $model->prepareData();
			$this->render('edit', $data );
			return;
		}

		if( ! $model->ValidateData( $_POST, $error ) ) {
			App::error($error);
			return false;
		}

		$model->insert($_POST);
		header('Location: index.php?q=author/index');
	}

	public function update() {
		$model = new author;
		if( !isset( $_POST['aut_id'] ) && isset($_GET['aut_id']) ) {
			$data = $model->prepareData($_GET['aut_id']);
			$this->render('edit', $data );
			return;
		}

		if( ! $model->ValidateData( $_POST, $error ) ) {
			App::error($error);
			return false;
		}

		$model->update($_POST);
		header('Location: index.php?q=author/index');
	}

	public function delete() {
		$model = new author;
		if( isset( $_GET['aut_id'] ) )
			$model->delete($_GET['aut_id']);

		header('Location: index.php?q=author/index');
	}

}
?>